<?php

namespace System;
class Container
{
    /**
     * 容器注入类，负责注入方法
     * @param $className
     * @param $fun
     * @throws \Exception
     */
    function call($className, $fun)
    {
        try {
            $rellection = new \ReflectionMethod($className, $fun);
            $parammeters = $rellection->getParameters();
            $params = array();
            foreach ($parammeters as $value) {
                $classContent = $value->getClass();
                $classText = $classContent->getName();
                $params[] = new $classText;
            }
            return call_user_func_array([new $className, $fun], $params);
        } catch (\ReflectionException $e) {
            throw new \Exception("（${className}中的${fun}方法）调用异常".$e->getMessage());
        }
    }
}
